home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 323 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  81 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: bwmott@unity.ncsu.edu
  3. Newsgroups: comp.std.c++
  4. Subject: Forward declaration of a sub-class?
  5. Date: 6 Feb 1996 22:20:35 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <199602062218.RAA08320@pythagoras.csc.ncsu.edu>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset="US-ASCII"
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: ELM [version 2.4 PL24/POP]
  14. X-Lines: 59
  15. Content-Length: 1277
  16. Originator: clamage@taumet
  17.  
  18.  
  19. I posted this to comp.std.c++, but I guess I was supposed to mail it
  20. so I'm mailing it now :-)
  21.  
  22. [ Posting should work. If it doesn't, contact your site administrator
  23.   to find out why. -mod ]
  24. --------------------------------------------------------------------------
  25.  
  26.  
  27. I've got a question about forward declaring a class as a sub-class of
  28. another class.  Is it possible under the C++ draft standard to do
  29. something like:
  30.  
  31.   class S;
  32.   class T : public S;
  33.  
  34. The reason I need such a thing is because of the restrictions placed on
  35. redefining the return type of a virtual function.
  36.  
  37. A simplified version of my class layout is:
  38.  
  39. class S;
  40. class T;  // This should be something to tell the compiler that
  41.           // class T exists and that it's a subclass of S.
  42.  
  43. class A {
  44.   public:
  45.     virtual S& belong() = 0;
  46. };
  47.  
  48. class B : public A {
  49.   public:
  50.     virtual T& belong();                 // This doesn't work but it seems
  51.                                          // that it should be possible!
  52.   private:
  53.     T& myT;
  54. };
  55.  
  56. class S {
  57.   public:
  58.     virtual A& get() = 0;
  59. };
  60.  
  61. class T : public S {
  62.   public:
  63.     virtual B& get();                   // This works fine
  64.   private:
  65.     B& myB;
  66. };
  67.  
  68. I guess a possible solution would be for the redefinition test to be done
  69. on the definition instead of on the declaration.
  70.  
  71. Is there any hope?
  72.  
  73. Thanks,
  74. Bradford Mott
  75.  
  76.  
  77. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  78.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  79.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  80. ]
  81.